<template>
	<view class="container">
		<!-- s收货地址 -->
		<view class="address">
			<view class="address_info">
				<label for="">收件人:{{ information.name }}</label>
				<label for="">{{ information.phone }}</label>
			</view>
			<view class="address_res">
				收货地址：<label for="">{{ information.address }}</label>
			</view>
		</view>

		<!-- 商品信息 -->
		<view class="carts">
			<!-- cartsInfo 循环体 -->
			<view class="cartsInfo" v-for="(item,index) in goodsCarts">
				<!-- 70px -->
				<view class="carts_detail">
					<view class="carts_image">
						<image :src="item.img" mode=""></image>
					</view>
					<view class="carts_name">
						<view for="" style="font-size: 30rpx;">{{item.goodsname}}</view>
						<view for="" style="font-size: 26rpx; color: #C0C0C0;">规格:白色</view>
					</view>
					<view class="carts_price">
						<label for="">￥{{item.price*item.num}}</label>
					</view>
				</view>
				<!-- 50px -->
				<view class="cart_num">
					<view class="">
						购买数量：
					</view>
					<view class="">
						<label for="" class="jian" @click="jian(index)">-</label>
						<label for="" class="num">{{item.num}}</label>
						<label for="" class="jia" @click="jia(index)">+</label>
					</view>
				</view>
				<!-- 横线 -->
				<view class="xian"></view>
			</view>
			<!-- 50px -->
			<view class="kuaidi">
				<label for="">配送方式</label>
				<label for="">XX快递</label>
			</view>
		</view>

		<!-- 优惠券 -->
		<view class="yhquan">
			<label for="">优惠券</label>
			<label for="" style="margin-right: 40rpx;">无可用</label>
		</view>
		<!-- jifen积分 -->
		<view class="jifen">
			<view class="use">
				<label for="">使用积分</label>
			</view>
			<view class="input" style="margin-right: 40rpx;">
				<input type="text" value="" placeholder="输入积分" />
				<label for="" class="input_use">使用</label>
				<label for="" class="input_keyi">可使用50积分</label>
			</view>
		</view>

		<!-- 具体详细 -->
		<view class="resDetail">
			<view class="">
				<label for="">商品金额</label>
				<label for="" style="margin-right:40rpx;color:red">￥420</label>
			</view>
			<view class="">
				<label for="">运费</label>
				<label for="" style="margin-right:40rpx;color:red">+￥0.00</label>
			</view>
			<view class="">
				<label for="">优惠券</label>
				<label for="" style="margin-right:40rpx;color:red">-￥0.00</label>
			</view>
			<view class="">
				<label for="">会员优惠</label>
				<label for="" style="margin-right:40rpx;color:red">-￥0.00</label>
			</view>
			<view class="">
				<label for="">积分抵扣</label>
				<label for="" style="margin-right:40rpx;color:red">-￥0.00</label>
			</view>
		</view>
		<!-- 实付金额 -->
		<view class="sfje">
			实付金额：<label for="" style="color:red">￥{{totalPrice}}</label>
		</view>

		<!-- 确认订单按钮 -->
		<view class="btn">
			<!-- 点击提交订单按钮，发起支付请求 -->
			<button type="primary" @click="present">提交订单</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				goodsCarts:[],
				num:1,
				information: {
					name: 'YouSu',
					phone: '15811112222',
					address: '北京市海淀区隐泉路清林苑6号'
				}
			}
		},
		onLoad() {
			this._goodsCarts()
		},
		methods: {
			jian(index) {
				this.goodsCarts[index].num--
				if (this.goodsCarts[index].num < 1) {
					this.goodsCarts[index].num = 1
				}
			},
			jia(index) {
				this.goodsCarts[index].num++
			},
			_goodsCarts(){
				this.goodsCarts = uni.getStorageSync("carts");
				console.log(this.goodsCarts)
			},
			// 提交订单
			async present(){
			
				let idArr = this.goodsCarts.map((item)=>{
					return item.id
				})
				console.log(idArr)
				let idstr = idArr.join();
				let params = {
					uid:uni.getStorageSync("uid"),
					username:this.information.name,
					userphone:this.information.phone,
					address:this.information.address,
					countmoney:this.totalPrice,
					countnumber:this.totalNum,
					addtime:new Date().getTime()
				}
				params = JSON.stringify(params)
				console.log(params,idstr,)
				let res = await this.$Api._orderadd({
					params,
					idstr
				},{authorization:uni.getStorageSync("token")})
				if(res.data.code == 200){
					uni.showToast({
						title:"提交成功"
					})
					setTimeout(()=>{
						uni.switchTab({
							url:"../index/index"
						})
					},1500)
				}
			}
		},
		computed:{
			totalPrice(){
				let total = 0;
				this.goodsCarts.forEach((v,i)=>{
					total += v.price * v.num
				})
				return total
			},
			totalNum(){
				let total = 0;
				this.goodsCarts.forEach((v,i)=>{
					total += v.num
				})
				return total
			}
		}
	}
</script>

<style>
	@import url("../../common/css/confirm.css");
</style>
